package com.taotao.search.listener;

import com.taotao.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class ItemChangeMessageListener implements MessageListener {
    @Autowired
    private SearchService searchService;

    @Override
    public void onMessage(Message message) {
        //判断消息的类型是否为TextMessage
        //获取商品id
        //通过id查询商品数据   需要开发mapper 通过id查询商品数据（搜索时）
        try {
            TextMessage textMessage = null;
            Long itemId = null;
            if (message instanceof TextMessage) {
                textMessage = (TextMessage) message;
                itemId = Long.parseLong(textMessage.getText());
            }
            searchService.updateSearchItemById(itemId);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
